
/*
* The constructor of Sprite.
* @param path (string) the path to image.
* @param id (string) the id of this Sprite.
* @param name (string) the name, if null is the same of id.
*/
function Sprite( id, path)
{
    this.path      = path;
    this.id        = id;
    this.name      = id;
    this.opacity   = 100;
    this.visible   = true;
    //Sprite.prototype = document.createElement('img');

    this.element   = document.createElement('img');
    this.element.name   = this.name;
    this.element.id     = this.id;
    this.element.src    = this.path

    document.body.appendChild( this.element );

    /*
    * Return the width of this Sprite.
    * @return the width of this Sprite.
    */
    this.getWidth = function()
    {
        return this.element.width;
    }


    /*
    * Defines the width of this Sprie
    * @param width, the new height of this Sprite
    */
    this.setWidth = function(width)
    {
        this.element.width = width;
    }


    /*
    * Return the height of this Sprite.
    * @return the height of this Sprite.
    */
    this.getHeight = function()
    {
        return this.element.height;
    }


    /*
    * Defines the Height of this Sprie
    * @param height, the new height of this Sprite
    */
    this.setHeight = function(height)
    {
        this.element.height = height;
    }

    /*
    * Return the opacity of this Sprite (0 to 100)
    * @return the opacity of this Sprite (0 to 100)
    */
    this.getOpacity = function()
    {
        return this.opacity;
    }

    /*
    * Defines the opacity of this Sprite.
    * @param opacity (int) 0 to 100.
    */
    this.setOpacity = function(opacity)
    {
        this.opacity = opacity;
        this.element.style.MozOpacity = opacity/100;
        this.element.style.Opacity    = opacity/100;
        this.element.style.filter     = 'alpha(opacity='+opacity+')';
    }


    /*
    * Return actual x position of this Sprite
    * @return x position of this Sprite.
    */
    this.getX = function()
    {
        var x = this.element.style.left;
        return parseInt(x.substring(0 , x.indexOf('px') ));
    }


    /*
    * Defines the x position of this Sprite
    * @param x position (integer)
    */
    this.setX = function(x)
    {
        this.element.style.position='absolute';
        this.element.style.left=x+'px';
    }


    /*
    * Return actual y position of this Sprite
    * @return y position of this Sprite.
    */
    this.getY = function()
    {
        var y = this.element.style.top;
        return parseInt(y.substring(0 , y.indexOf('px') ));
    }


    /*
    * Defines the y position of this Sprite
    * @param y position (integer)
    */
    this.setY = function(y)
    {
        this.element.style.position='absolute';
        this.element.style.top=y+'px';
    }


    /*
    * Returns a String with Sprites parameters.
    * @return a string with Sprite parameters.
    */
    this.toString = function()
    {
        return this.id+'= X/Y='+this.getX()+'/'+this.getY()+' Width/Height='+this.getWidth() + '/' + this.getHeight() +' Opacity=' + this.opacity +' Layer=' + this.getLayer()
    }


    /*
    * Defines the actual layer of this Sprite.
    * @param layer (int).
    */
    this.setLayer = function(layer)
    {
        this.element.style.zIndex=layer
    }

    /*
    * Returns the actual layer of this Sprite.
    *
    */
    this.getLayer = function()
    {
         return this.element.style.zIndex;
    }


    /*
    * Set the visibility of this Sprite.
    * @param visible (true or false)
    */
    this.setVisible = function(visible)
    {
       if (visible == true)
       {
            this.element.style.display='block';
            this.visible=true;
       }
       else
       {
            this.element.style.display='none';
            this.visible=false;
       }
    }


    /*
    * Hides the Sprite, or change it visibility false.
    *
    */
    this.hide = function()
    {
        this.element.style.display='none';
        this.visible=false;

    }


    /*
    * Turn visibility of Sprite On, or Show it.
    * Internaly sets visible = true.
    */
    this.show = function()
    {
        this.element.style.display='block';
        this.visible=true;
    }


    /*
    *   Return if Sprite is visible or not.
    *   @return True or False.
    */
    this.getVisible = function()
    {
        return this.visible;
    }

    this.setScaleX  = function()
    {

    }
}
